package com.emergency.db.controller.item;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.item.ItemLocation;
import com.emergency.db.domain.staff.StaffLocation;
import com.emergency.db.service.item.ItemLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/item/location")
@CrossOrigin
public class ItemLocationController {
    @Autowired
    private ItemLocationService itemLocationService;

    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody ItemLocation itemLocation) {
        Long id = itemLocationService.save(itemLocation);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //删除
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    public Result del(@PathVariable("id") Long id) {
        itemLocationService.deleteAllByItem(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    //分页
    @RequestMapping(value = "/list/{id}/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable Long id, @PathVariable int page, @PathVariable int size) {
        Page<ItemLocation> pageList = itemLocationService.findList(searchMap, page, size, id);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }

}
